<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Gym Rat | Modify Routine ${routine.name }</title>
</head>
<body>
<jsp:include page="/includes/nav.jsp" />
<div class="result">${result }</div>
<h1>Modifying Routine: ${routine.name }</h1>
<ul>
	<li>Add entries to this routine using the <a
		href="<c:url value='addentry?routine=${routine.id }' />">Add
	Exercise</a> link below.</li>
	<li>Modify an entry by clicking on the exercise name. There you
	can edit the variations, sets, reps, etc.</li>
	<li>Delete entries by using the checkboxes on the right hand
	column of the table and the "Delete" button below.</li>
	<li>Rename or delete this routine using the form at the bottom of
	the page.</li>
	<c:if test="${routine.sourceId != 0 }">
		<li>This is a copy of another user's <a
			href="<c:url value='/routine/view?id=${routine.id }' />">Shared
		Routine</a>, you may want to check to see if they have made updates to it</li>
	</c:if>
</ul>
<h2>Entries in this Routine:</h2>
<form action="deleteentries" method="post">
<table width="100%">
	<tr class="tableHeader">
		<td>Exercise</td>
		<td>Variations</td>
		<td>Muscle Group</td>
		<td>Order</td>
		<td>Sets</td>
		<td>Reps</td>
		<td>Delete?</td>
	</tr>

	<c:if test="${routine != null}">
		<c:forEach var="entry" items="${routine.entries}" varStatus="status">
			<c:choose>
				<c:when test="${status.count % 2 == 1 }">
					<c:set var="rowClass" value="tableOddRow" />
				</c:when>
				<c:otherwise>
					<c:set var="rowClass" value="tableEvenRow" />
				</c:otherwise>
			</c:choose>
			<tr class="${rowClass}">
				<td><a
					href="<c:url value='editEntry?routineid=${routine.id }&entryid=${entry.id}' />">${entry.exercise}</a></td>
				<td><c:forEach var="variation" items="${entry.variations }">
				${variation.value},
				</c:forEach></td>
				<td>${entry.muscleGroup}</td>
				<td>${entry.order}</td>
				<td>${entry.sets}</td>
				<td>${entry.reps}</td>
				<td><input type="checkbox" name="deletebox"
					value="${entry.id }" /></td>
			</tr>
		</c:forEach>
	</c:if>
	<tr class="tableHeader">
		<td><a class="headerLink"
			href="<c:url value='addentry?routine=${routine.id }' />">Add
		Exercise to this Routine</a></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td><input type="hidden" name="routineId" value="${routine.id}"></td>
		<td><input type="button" name="deletedentries" value="Delete"
			onClick="if(confirm('Really delete entries?'))
	submit()" /></td>
	</tr>
</table>
</form>
<hr />
<h2>Edit this Routine:</h2>
<form action="modify/submit" method="post">
<table>
	<tr>
		<td>Name:</td>
		<td><input type="text" name="newName" value="${routine.name }"></td>
	</tr>
	<tr>
		<td>Description:</td>
		<td><textarea rows="3" cols="25" name="newDesc">${routine.description }</textarea></td>
	</tr>
	<tr>
		<td>Author</td>
		<td><input type="text" name="newAuthor" value="${routine.author}"></td>
	</tr>
	<tr>
		<td>Primary Muscle Group:</td>
		<td><select name="primary">
			<option value="-1">---</option>
			<option value="0"
				<c:if test="${routine.primary == 0 }">
				selected="selected"</c:if>>Total
			Body</option>
			<c:forEach var="group" items="${groups}">
				<option value="${group.key}"
					<c:if test="${routine.primary == group.key }">
				selected="selected"</c:if>>${group.value}</option>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td>Secondary Muscle group:</td>
		<td><select name="secondary">
			<option value="-1">---</option>
			<c:forEach var="group" items="${groups}">
				<option value="${group.key}"
					<c:if test="${routine.secondary == group.key }">
				selected="selected"</c:if>>${group.value}</option>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td>Share this routine?</td>
		<td><input type="checkbox" name="sharecheck" value="true"
			<c:if test="${routine.shared == true }">
		checked="checked"
		</c:if> />
		<c:if test="${routine.shared == true}">
		This routine is currently shared and used by ${routine.users } users.
		</c:if></td>
	</tr>

	<tr>
		<td><input type="submit" value="Update"></td>
		<td><input type="hidden" name="delete" value="false"></td>
		<td><input type="hidden" name="id" value="${routine.id }"></td>
	</tr>
</table>
</form>
<form action="modify/submit" method="post"><input type="hidden"
	name="delete" value="true"> <input type="button" value="Delete"
	onClick="if(confirm('Really delete routine and ALL of the entries?'))
	submit()">
<input type="hidden" name="newName" value="${routine.name }"> <input
	type="hidden" name="id" value="${routine.id }"></form>
</body>
</html>